package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    @Override
    public Result findByRids(Integer[] roleIds) {
        try {
            //不可重复
            Set<Integer> integers = new HashSet<>();
            for (Integer roleId : roleIds) {
                List<Permission> permissionList = permissionDao.findByRids(roleId);
                for (Permission permission : permissionList) {
                    Integer id = permission.getId();
                    integers.add(id);
                }
            }
            return new Result(true,"获取权限信息成功",integers);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"获取权限信息失败");
        }
    }

}
